// pages/questionnaire/questionnaire.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    nav:"下一页",
    currentTab:0,
    name:"无名氏",
    sex:"男",
    birthday:"2000-06-15",
    device:[
      {name:"0",value:"台式电脑"},
      {name:"1",value:"笔记本电脑"},
      {name:"2",value:"平板电脑"},
      {name:"3",value:"智能手机"},
      {name:"4",value:"智能手表"}
    ],
    time: [
      { name: "0", value: "少于一小时" },
      { name: "1", value: "一到三小时" },
      { name: "2", value: "三到五小时" },
      { name: "3", value: "五到八小时" },
      { name: "4", value: "八小时以上" }
    ],
    deviceResult:[],
    timeResult:"少于一小时",
    opinion:""

  },
  nextTab:function(){
    var maxTab=5
    var ct=this.data.currentTab+1
    if(ct==maxTab-1){
      this.setData({nav:"请点击提交"})
      return false
    }else if(ct>=maxTab){
      this.setData({nav:"调查问卷"})
      return false
    }
    this.setData({currentTab:ct})
  },
  noMove:function(res){
    return false
  },
  dateChange:function(e){
    this.setData({birthday:e.detail.value})
  },
  formSubmit:function(e){
    var name=e.detail.value.name
    var sex=e.detail.value.sex=="male"?"男":"女"
    var birthday=e.detail.value.birthday
    var device=e.detail.value.device
    var time=e.detail.value.time
    var opinion=e.detail.value.opinion
    var deviceResult=[]
    var timeResult="少于一小时"
    for(var i=0;i<device.length;i++){
      deviceResult.push(this.data.device[device[i]].value)
    }
    timeResult=this.data.time[time].value
    this.setData({
      currentTab:this.data.currentTab+1,
      nav:"问卷结果",
      name:name,
      sex:sex,
      birthday:birthday,
      devicceResult:deviceResult,
      timeResult:timeResult,
      opinion:opinion

    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})